import Vue from "vue";
import VueRouter from "vue-router";

// 一级路由
import Home from "../views/Home";
import Login from "../views/Login";

// 二级路由
import News from "../views/Home/News";
import Game from "../views/Home/Game";
import Movie from "../views/Home/Movie";



Vue.use(VueRouter);

// 解决重复点击报错
const init = VueRouter.prototype.push;
VueRouter.prototype.push = function (location, i = () => { }, b = () => { }) {
  init.call(this, location, i, b);
};

const init1 = VueRouter.prototype.replace;
VueRouter.prototype.replace = function (location, i = () => { }, b = () => { }) {
  init1.call(this, location, i, b);
};

export default new VueRouter({

  routes: [
    {
      path: "/home",
      component: Home,
      redirect: "/home/news",
      // 二级路由
      children: [
        {
          path: "news",
          component: News,
          name: "news"
        },
        {
          path: "game",
          component: Game,
          name: "game",

        },
        {
          path: "movie",
          component: Movie,
          name: "movie"
        },
      ]
    },
    {
      path: "/login",
      component: Login,
      name: "login"
    },
    {
      path: "/",
      // 路由重定向
      redirect: "/home"
    }
  ]
});